package com.nest4cloud.nest.account.mapper;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.nest4cloud.nest.account.entity.AccTransactionsEntity;
import com.nest4cloud.nest.account.vo.accTransaction.MouthTransactions;
import com.nest4cloud.nest.account.vo.accTransaction.MouthTransactionsItem;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface AccTransactionsMapper extends BaseMapper<AccTransactionsEntity> {

    List<MouthTransactions> queryTotalTransactionsGroupByMouthAccountId(@Param("accountId") Long accountId);

    @ResultMap("dayTransactionsMap")
    @Select("SELECT \n" +
            "    DATE_FORMAT(t.`date`, '%m-%d') AS `transaction_mouth_day`,\n" +
            "    a.`account_name`,\n" +
            "    c.`id` AS `category_id`,\n" +
            "    c.`name` AS `category_name`,\n" +
            "    t.`account_id`,\n" +
            "    t.`transaction_type`,\n" +
            "    t.`date` AS `transaction_time`,\n" +
            "    t.`amount`,\n" +
            "    t.`description`\n" +
            "FROM \n" +
            "    `acc_transactions` t\n" +
            "JOIN \n" +
            "    `acc_accounts` a ON t.`account_id` = a.`id`\n" +
            "JOIN \n" +
            "    `acc_categories` c ON t.`category_id` = c.`id`\n" +
            "WHERE \n" +
            "    t.`account_id` = #{accountId}\n" +
            "    AND t.`del_flag` = '0'\n" +
            "    AND DATE_FORMAT(t.`date`, '%Y年%m月') = #{transactionYearMouth}\n" +
            "ORDER BY \n" +
            "    `transaction_mouth_day` DESC,\n" +
            "    t.`date` DESC;\n")
    List<MouthTransactionsItem> queryTransactionsGroupByMouthAccountId(@Param("accountId") Long accountId, @Param("transactionYearMouth") String transactionYearMouth);
}
